﻿<%@ Page Language="C#" CodeBehind="Categories.aspx.cs" Inherits="d3PrtDgn.Web.Admin.Categories" MasterPageFile="~/Web/Admin/AdminTemplate.Master" %>
<asp:Content id="body" contentPlaceholderId="body" runat="server">
	<script type="text/javascript">
		function confirmDelete()
		{
			return confirm('<%= GetMessage("reallyDelete") %>')		
		}

		function client_OnTreeNodeChecked()
		{
			var obj = window.event.srcElement;
			var treeNodeFound = false;
			var checkedState;
			if (obj.tagName == "INPUT" && obj.type == "checkbox")
			{
				var treeNode = obj;
				checkedState = treeNode.checked;
				do
				{
					obj = obj.parentElement;
				} while (obj.tagName != "TABLE")

				var parentTreeLevel = obj.rows[0].cells.length;
				var parentTreeNode = obj.rows[0].cells[0];
				var tables = obj.parentElement.getElementsByTagName("TABLE");
				var numTables = tables.length

				if (numTables >= 1)
				{
					for (i=0; i < numTables; i++)
					{
						if (tables[i] == obj)
						{
							treeNodeFound = true;
							i++;
							if (i == numTables)
							{
								return;
							}
						}

						if (treeNodeFound == true)
						{
							var childTreeLevel = tables[i].rows[0].cells.length;
							if (childTreeLevel > parentTreeLevel)
							{
								var cell = tables[i].rows[0].cells[childTreeLevel - 1];
								var inputs = cell.getElementsByTagName("INPUT");
								inputs[0].checked = checkedState;
							}
							else
							{
								return;
							}
						}
					}
				}
			}
		}
	</script>
	<h2><%= GetMessage("mainHeader") %></h2>
	
	<h3><%= GetMessage("categoryListHeader") %></h3>
	<asp:TreeView runat="server" id="tvCategories" OnSelectedNodeChanged="EditCategory" ShowCheckBoxes="All" onclick="client_OnTreeNodeChecked();">
		<DataBindings>
			<asp:TreeNodeBinding TextField="Name" ValueField="Id" />
		</DataBindings>
	</asp:TreeView>
	<asp:Button runat="server" ID="btnDeleteSelected" OnClientClick="return confirmDelete()" OnClick="Delete" />

	<h3><%= GetMessage("categoryEditHeader") %></h3>
	<asp:Table runat="server">
		<asp:TableRow>
			<asp:TableHeaderCell CssClass="leftHeader"><asp:Label runat="server" ID="lblParent" />:</asp:TableHeaderCell>
			<asp:TableCell><asp:DropDownList runat="server" ID="ddlParent" DataTextField="Name" DataValueField="Id" /></asp:TableCell>
		</asp:TableRow>
		<asp:TableRow>
			<asp:TableHeaderCell CssClass="leftHeader"><asp:Label runat="server" ID="lblName" />:</asp:TableHeaderCell>
			<asp:TableCell><asp:TextBox runat="server" ID="tbName" /></asp:TableCell>
			<asp:TableCell CssClass="error"><spring:ValidationError runat="server" ID="nameErrors" /></asp:TableCell>
		</asp:TableRow>
		<asp:TableRow>
			<asp:TableHeaderCell CssClass="leftHeader"><asp:Label runat="server" ID="lblAbbreviation" />:</asp:TableHeaderCell>
			<asp:TableCell><asp:TextBox runat="server" ID="tbAbbreviation" Enabled="false" /></asp:TableCell>
		</asp:TableRow>
		<asp:TableRow>
			<asp:TableHeaderCell CssClass="leftHeader"><asp:Label runat="server" ID="lblDescription" />:</asp:TableHeaderCell>
			<asp:TableCell><asp:TextBox runat="server" ID="tbDescription" /></asp:TableCell>
		</asp:TableRow>
		<asp:TableRow>
			<asp:TableCell ColumnSpan="2">
				<asp:Button runat="server" ID="btnSave" OnClick="Save" />
				<asp:Button runat="server" ID="btnCancel" OnClick="Cancel" />
			</asp:TableCell>
		</asp:TableRow>
	</asp:Table>
</asp:Content>